package br.pucrio.inf.aaaong.models.domain.form.validation;

import java.util.ArrayList;
import java.util.List;

import br.pucrio.inf.aaaong.models.domain.form.beans.TelefoneFormBean;
import br.pucrio.inf.aaaong.models.form.errors.FormError;
import br.pucrio.inf.aaaong.models.form.validation.FormValidation;

public class NumerosEResponsaveisValidation implements FormValidation {

	private static final String ERROR_MESSAGE = "deve ter número e responsável.";

	@Override
	public List<FormError> getErrors(Object telefones, String fieldName) {
		List<FormError> errors = new ArrayList<FormError>();
		
		for (TelefoneFormBean telefone : (List<TelefoneFormBean>) telefones) {
			if ((telefone.getNumero() != null && telefone.getResponsavel() == null)
			 || (telefone.getNumero() == null && telefone.getResponsavel() != null)) {
				errors.add(new FormError(ERROR_MESSAGE, fieldName));
				break;
			}			
		}

		return errors;
	}

}
